package com.hb.utils;

import org.junit.Assert;
import org.springframework.mock.web.MockHttpServletRequest;

import static org.junit.Assert.*;

public class IpUtilsTest {

    @org.junit.Before
    public void setUp() throws Exception {
    }

    @org.junit.Test
    public void getIPAddress() {
        MockHttpServletRequest request = new MockHttpServletRequest();

        String Null_result=IpUtils.getIPAddress(null);
        assertEquals("unknown",Null_result);

        request.addHeader("x-forwarded-for","202.100.100.100");
        String xForwardResult=IpUtils.getIPAddress(request);
        assertEquals("202.100.100.100",xForwardResult);

        MockHttpServletRequest request1 = new MockHttpServletRequest();
        request1.addHeader("Proxy-Client-IP","108.100.100.1");
        String proxyClientResult=IpUtils.getIPAddress(request1);
        assertEquals("108.100.100.1",proxyClientResult);

        MockHttpServletRequest request2 = new MockHttpServletRequest();
        request2.addHeader("X-Forwarded-For","108.100.100.1");
        String XForwardResult=IpUtils.getIPAddress(request2);
        assertEquals("108.100.100.1",XForwardResult);

        MockHttpServletRequest request3 = new MockHttpServletRequest();
        request3.addHeader("WL-Proxy-Client-IP","108.100.100.1");
        String wLProxyClientResult=IpUtils.getIPAddress(request3);
        assertEquals("108.100.100.1",wLProxyClientResult);

        MockHttpServletRequest request4 = new MockHttpServletRequest();
        request4.addHeader("X-Real-IP","104.100.100.1");
        String XRealResult=IpUtils.getIPAddress(request4);
        assertEquals("104.100.100.1",XRealResult);

        MockHttpServletRequest request5 = new MockHttpServletRequest();
        request5.setRemoteAddr("104.100.100.1");
        String remoteAddrResult=IpUtils.getIPAddress(request5);
        assertEquals("104.100.100.1",remoteAddrResult);

    }
}